using System.Collections.Generic;
using VoxelGame.Character;

namespace PKGames.Voxel.Analytics
{
	public class ToolInteractionEventGroup
	{
		private readonly Dictionary<CharacterToolsController.ToolData.Tools, ToolInteractionEvent> _toolInteractions = new Dictionary<CharacterToolsController.ToolData.Tools, ToolInteractionEvent>();

		public void OnToolUse(CharacterToolsController.ToolData.Tools toolType)
		{
			if (!_toolInteractions.ContainsKey(toolType))
			{
				_toolInteractions[toolType] = new ToolInteractionEvent(toolType);
			}
			foreach (ToolInteractionEvent value in _toolInteractions.Values)
			{
				if (value.ToolType == toolType)
				{
					value.ToolUseStarted();
				}
				else
				{
					value.ToolUseStopped();
				}
			}
		}

		public void BlockAdded(CharacterToolsController.ToolData.Tools toolUsed)
		{
			if (!_toolInteractions.ContainsKey(toolUsed))
			{
				_toolInteractions[toolUsed] = new ToolInteractionEvent(toolUsed);
			}
			_toolInteractions[toolUsed].BlockAdded();
		}

		public void BlockRemoved(CharacterToolsController.ToolData.Tools toolUsed, int count)
		{
			if (!_toolInteractions.ContainsKey(toolUsed))
			{
				_toolInteractions[toolUsed] = new ToolInteractionEvent(toolUsed);
			}
			_toolInteractions[toolUsed].BlockRemoved(count);
		}

		public void FinishAndLog()
		{
			foreach (ToolInteractionEvent value in _toolInteractions.Values)
			{
				value.Finish();
				value.LogIfValid();
			}
		}
	}
}
